package org.ch02.sk.demo10;

import java.beans.*;
import java.lang.reflect.Method;

/**
 * @author XCH
 * @date 2025 - 03 - 25
 */
public class MainTest {
    public static void main(String[] args) throws Exception {
        Person person = new Person("张三", 20);
        BeanInfo beanInfo = Introspector.getBeanInfo(person.getClass(), Object.class);
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        //MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
        for (PropertyDescriptor propertyDescriptor : propertyDescriptors){
            String name = propertyDescriptor.getName();
            Method readMethod = propertyDescriptor.getReadMethod();
            if (readMethod != null){
                Object value = readMethod.invoke(person);
                System.out.println(name + "=" + value);
            }
        }
    }
}
